<template>
  <el-container class="homecontainer">
    <!-- 头部布局 -->
    <el-header>
      <div>
        <img class="logo" src="../assets/code4.jpg" alt="" />
        <span>Acm判题后台系统</span>
      </div>
      <el-button @click="loginOut" type="info">注销</el-button>
    </el-header>

    <!-- 下面主体布局 -->
    <el-container>

     
      <!-- 左边菜单布局 -->
      <el-aside :width="isCollapse? '64px' : '200px'">
        
        <!-- 设置菜单折叠的组件 -->
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!--主菜单组件-->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409fff"
          unique-opened
         :collapse="isCollapse"
         :collapse-transition="false"
         router
         :default-active="$route.path"
        >
          <!--  一级菜单第一个菜单组件  -->
          <el-submenu
            :index="item.id + ''"
             v-for="item in menulist"
            :key="item.id"
          >
            <!-- 菜单的图标和文字信息 -->
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ item.authName }}</span>
            </template>

            <!-- 二级子菜单条目 -->
            <el-menu-item
              :index="'/'+subMenu.path"
              v-for="subMenu in item.children"
              :key="subMenu.id"
            >
              <!-- 菜单的图标和文字信息 -->
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ subMenu.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <!-- 右边内容主区域布局 -->
      <el-main>
         <!-- 设置路由占位符 -->
         <router-view></router-view>
      </el-main>


    </el-container>
  </el-container>
</template>

<script>    
export default {
  created() {
    this.getMenuList();
  },
  data() {
    return {
      menulist: [],
      isCollapse: false
    }
  },
  methods: {
    loginOut() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },

    async getMenuList() {
      const { data: res } = await this.$http.get("menus");
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg);
      }
      this.menulist = res.data;
    },

    toggleCollapse(){
        this.isCollapse =!this.isCollapse;
    }
  }
};
</script>

<style lang="less" scope>
.logo {
  margin-left: -15px;
  width: 50px;
  height: 50px;
  border-radius: 30%;
}

.homecontainer {
  height: 100%;
}

.el-header {
  background-color: #373d41;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 0px;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;

    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #eaedf1;
}

.toggle-button{
    background-color: #4A5064;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
}
</style>
